package com.eascs.p2p.admin.service.impl;

import javax.inject.Inject;

import com.alibaba.dubbo.config.annotation.Service;
import com.eascs.app.dao.PageResult;
import com.eascs.p2p.admin.manager.ILoaneeManager;
import com.eascs.p2p.common.entity.LoaneeEntity;
import com.eascs.p2p.common.service.ILoaneeService;
import com.eascs.p2p.common.vo.LoaneeVO;
import com.eascs.p2p.common.vo.ModelResult;

@Service
public class LoaneeServiceImpl implements ILoaneeService {
	@Inject
	ILoaneeManager loaneeManager;

	@Override
	public ModelResult<PageResult<Object[]>> findPageLoaneeEntity(LoaneeVO vo) {
		
		ModelResult<PageResult<Object[]>> result = new ModelResult<PageResult<Object[]>>();
		try {
			result.setModel(loaneeManager.findPageLoaneeEntity(vo));
		} catch (Exception e) {
			e.printStackTrace();
			result.withError("借款人分页查询：", e.getMessage());
		}
		return result;
	}

	@Override
	public ModelResult<String> addLoaneeEntity(LoaneeEntity loaneeEntity) {
		ModelResult<String> result = new ModelResult<String>();
		try {
			result.setModel(loaneeManager.addLoaneeEntity(loaneeEntity));
		} catch (Exception e) {
			e.printStackTrace();
			result.withError("添加借款人：", e.getMessage());
		}
		return result;
	
	}

	@Override
	public  ModelResult<Boolean> updateLoaneeEntity(LoaneeEntity loaneeEntity) {
		ModelResult<Boolean> result = new ModelResult<Boolean>();
		try {
			result.setModel(loaneeManager.updateLoaneeEntity(loaneeEntity));
		} catch (Exception e) {
			e.printStackTrace();
			result.withError("更新借款人：", e.getMessage());
		}
		return result;
	}

	@Override
	public ModelResult<LoaneeEntity> findLoaneeEntityDetail(String id) {
		ModelResult<LoaneeEntity> result = new ModelResult<LoaneeEntity>();
		try {
			result.setModel(loaneeManager.findLoaneeEntityDetail(id));
		} catch (Exception e) {
			e.printStackTrace();
			result.withError("借款人详情：", e.getMessage());
		}
		return result;
	
	}

	@Override
	public ModelResult<LoaneeVO> getLoaneeNum(LoaneeVO vo) {
		ModelResult<LoaneeVO> result = new ModelResult<LoaneeVO>();
		try {
			result.setModel(loaneeManager.getLoaneeNum(vo));
		} catch (Exception e) {
			e.printStackTrace();
			result.withError("查询借款人总数和总金额：", e.getMessage());
		}
		return result;
	}

	@Override
	public ModelResult<Integer> getLoaneeEntity(LoaneeVO vo) {
		ModelResult<Integer> result = new ModelResult<Integer>();
		try {
			result.setModel(loaneeManager.getLoaneeEntity(vo));
		} catch (Exception e) {
			e.printStackTrace();
			result.withError("查询手机号码或者身份证号码是否已经存在：", e.getMessage());
		}
		return result;
	}

	@Override
	public ModelResult<Integer> getTotalAmount(LoaneeVO vo) {
	
		ModelResult<Integer> result = new ModelResult<Integer>();
		try {
			result.setModel(loaneeManager.getTotalAmount(vo));
		} catch (Exception e) {
			e.printStackTrace();
			result.withError("查询贷款总金额：", e.getMessage());
		}
		return result;
	}
	
	
}
